﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Data;
using System.Globalization;
using System.Xml.Serialization;

namespace AssignmentsManage.Converters
{
    public class StringToTitleValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                string seperator = parameter.ToString();
                string str = (string)value;
                string[] split = str.Split('\t');

                if (parameter.ToString() == "Title")
                {
                    return split[0];
                }
                else
                {
                    return (object)split[1]; 
                }
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                string seperator = parameter.ToString();
                string str = (string)value;
                string[] split = str.Split('\t');

                if (parameter.ToString() == "Title")
                {
                    return split[0];
                }
                else
                {
                    return (object)split[1];
                }
            }

            return null;
        }
    }
}
